(function (win, dom) {
    function Alert(config) {
        if (!config) return;
        this.condition = config.condition;
        this.successFn = config.successFn;
        this.faillFn = config.faillFn;
        this.leftText = config.leftText;
        this.rightText = config.rightText;
        this.init();
    }

    Alert.prototype = {
        constructor: Alert,
        //创建元素
        init: function () {
            this.container = dom.createElement('div');
            this.container.className = 'containerHint';
            this.contend = dom.createElement('div');
            this.contend.innerHTML = this.condition;
            this.contend.className = 'contendHint';
            this.contendBnt = dom.createElement('div');
            this.contendBnt.className = 'contendBnt';
            this.leftBnt = dom.createElement('a');
            this.leftBnt.innerHTML = this.leftText;
            this.leftBnt.className = 'leftBnt';
            this.bindEv(this.leftBnt, this.successFn);
            this.rightBnt = dom.createElement('a');
            this.rightBnt.innerHTML = this.rightText;
            this.rightBnt.className = 'rightBnt';
            this.bindEv(this.rightBnt, this.faillFn);
            this.append();
        },
        //添加元素
        append: function () {
            this.contendBnt.appendChild(this.leftBnt);
            this.contendBnt.appendChild(this.rightBnt);
            this.container.appendChild(this.contend);
            this.container.appendChild(this.contendBnt);
            dom.body.appendChild(this.container);
        },
        //创建事件
        bindEv: function (doc, fn) {
            var that = this;
            doc.onclick = function () {
                fn && fn();
                that.container.style.display = 'none';
            }
        }

    };


    function AddAlert(config) {
        Alert.call(this,config);
       this.hint = config.hint;
       this.newhint = dom.createElement('div');
       this.newhint.innerHTML = this.hint;
        this.newhint.className = 'hint';
       this.container.insertBefore(this.newhint, this.contend);
    }

    AddAlert.prototype = new Alert();
    AddAlert.prototype.constructor = AddAlert;


    function ImgAlert(suss){
        if(!suss) return ;
        var fragment = dom.createDocumentFragment();
        this.img_div = dom.createElement('div');
        this.img_div.className = 'img_div';
        this.img_ensure = dom.createElement('div');
        this.img_ensure.id = 'img_en';
        this.img_div.appendChild(this.img_ensure);
        fragment.appendChild(this.img_div);
        dom.body.appendChild(fragment);
        suss['type'] === 'success'?this.img_ensure.className = 'img_ensure': this.img_ensure.className = 'img_loding';
    }
    ImgAlert.prototype.timer = function (num) {
        if(!num) num = 3000;
            var that  = this ;
            setTimeout(function () {
                that.img_div.style.display = 'none';
            },+num)
    };
    win['Alert'] = Alert;
    win['AddAlert'] = AddAlert;
    win['ImgAlert'] = ImgAlert ;
})(window, document, undefined);
